package net.liteheaven.dtimer.misc;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

import net.liteheaven.dtimer.XLog;

/**
 * 测试在android8.0会不会被停止
 * Created by LiangYu on 2018/8/3.
 */
public class CommonService extends Service {

    public static final String ACTION_REBORN = "net.liteheaven.dtimer.ACTION_REBORN";

    @Override
    public void onCreate() {
        super.onCreate();
        XLog.i("CommonService::onCreate");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        XLog.i("CommonService::onDestroy");
        sendRebornBroadcast(getApplicationContext());
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        XLog.i("CommonService::onBind");
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
        //return START_STICKY;
    }

    public static void sendRebornBroadcast(Context context){
        context.sendBroadcast(new Intent(ACTION_REBORN));
    }
}
